package com.future.baselib.utils;

import android.util.Log;

import com.future.baselib.BuildConfig;

/**
 * 程序中用到的打印日志类统一使用FLog
 * Created by jniu on 2017/12/18 0018.
 */

public class FLog {

    private static String className;
    private static String methodName;
    private static int lineNumber;

    public static void v(String msg) {
        if (!BuildConfig.DEBUG) {
            return;
        }
        getMethodName(new Throwable().getStackTrace());
        Log.v(className,createLog(msg));
    }

    public static void d(String msg){
        if (!BuildConfig.DEBUG) {
            return;
        }
        getMethodName(new Throwable().getStackTrace());
        Log.d(className,createLog(msg));
    }

    private static String createLog(String msg) {
        return String.format("[ %s : %s ] %s",methodName,lineNumber,msg);
    }

    private static void getMethodName(StackTraceElement[] stackTrace) {
        className = stackTrace[1].getClassName();
        methodName = stackTrace[1].getMethodName();
        lineNumber = stackTrace[1].getLineNumber();
    }

    public static void i(String msg) {
        if (!BuildConfig.DEBUG) {
            return;
        }
        getMethodName(new Throwable().getStackTrace());
        Log.i(className,createLog(msg));
    }

    public static void w(String msg) {
        if (!BuildConfig.DEBUG) {
            return;
        }
        getMethodName(new Throwable().getStackTrace());
        Log.w(className,createLog(msg));
    }

    public static void e(String msg) {
        if (!BuildConfig.DEBUG) {
            return;
        }
        getMethodName(new Throwable().getStackTrace());
        Log.e(className,createLog(msg));
    }
}
